<!-- components/Navbar.vue -->
<template>
  <nav class="navbar">
    <div class="container">
      <!-- Logo -->
      <!-- <NuxtLink to="/" class="logo">
        <img src="/logo.png" alt="Logo">
      </NuxtLink> -->

      <!-- 桌面导航 -->
      <div class="desktop-menu">
        <NuxtLink 
          v-for="(item, index) in navItems" 
          :key="index"
          :to="item.path"
          class="nav-link"
          active-class="active"
        >
          {{ item.title }}
        </NuxtLink>
      </div>

      <!-- 移动端汉堡菜单 -->
      <button class="hamburger" @click="toggleMenu">
        <div class="bar"></div>
        <div class="bar"></div>
        <div class="bar"></div>
      </button>

      <!-- 移动端菜单 -->
      <div v-show="isMenuOpen" class="mobile-menu">
        <NuxtLink
          v-for="(item, index) in navItems"
          :key="index"
          :to="item.path"
          class="mobile-link"
          @click="closeMenu"
        >
          {{ item.title }}
        </NuxtLink>
      </div>
    </div>
  </nav>
</template>

<script setup>
const navItems = ref([
  { title: '首页', path: '/' },
  { title: '产品', path: '/products' },
  { title: '关于我们', path: '/about' },
  { title: '联系我们', path: '/contact' }
])

const isMenuOpen = ref(false)

const toggleMenu = () => {
  isMenuOpen.value = !isMenuOpen.value
}

const closeMenu = () => {
  isMenuOpen.value = false
}
</script>

<style scoped>
.navbar {
  position: fixed;
  top: 0;
  width: 100%;
  background: rgba(0,0,0,0.1);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  z-index: 1000;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo img {
  height: 40px;
}

.desktop-menu {
  display: flex;
  gap: 2rem;
}

.nav-link {
  padding: 0.5rem 1rem;
  transition: color 0.3s ease;
}

.nav-link:hover,
.active {
  color: #2563eb;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
}

.bar {
  width: 25px;
  height: 3px;
  background: #333;
  margin: 4px 0;
  transition: 0.3s;
}

.mobile-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  padding: 1rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.mobile-link {
  display: block;
  padding: 1rem;
  text-align: center;
}

@media (max-width: 768px) {
  .desktop-menu {
    display: none;
  }

  .hamburger {
    display: block;
  }

  .mobile-menu {
    display: block;
  }
}
</style>